/* ----------------------------------------------------------------------
*
* Copyright (C) 2025 XiaoFei. All rights reserved.
*
* $file:		XiaoFei_Usart1.h
* $Date:        16-January-2025
* $Revision: 	V1
* $Project: 	XiaoFei BSP Library
* $Taobao:      https://item.taobao.com/item.htm?abbucket=17&id=815798494362
*
* -------------------------------------------------------------------- */

#ifndef __XiaoZhi_OLED_H
#define __XiaoZhi_OLED_H

#define OLED_UseI2C

#ifdef OLED_UseI2C
	#define OLED_GPIO_SDA				GPIOC
	#define OLED_PIN_SDA				GPIO_Pin_0
	#define OLED_GPIO_SCL				GPIOC
	#define OLED_PIN_SCL				GPIO_Pin_1
	#define OLED_Device_ID				0x78
	#define OLED_WrCommand_Code		    0x00
	#define OLED_WrData_Code			0x40
	#define OLED_SDA_RCC(x)				RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC,(FunctionalState)x)
	#define OLED_SCL_RCC(x)				RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC,(FunctionalState)x)
	#define OLED_SCL(x)					do{GPIO_WriteBit(OLED_GPIO_SCL,OLED_PIN_SCL,(BitAction)(x));XiaoFei_Delay_us(1);}while(0)
	#define OLED_SDA(x)					do{GPIO_WriteBit(OLED_GPIO_SDA,OLED_PIN_SDA,(BitAction)(x));XiaoFei_Delay_us(1);}while(0)
#endif

#define OLED_CursorY					0xB0
#define OLED_CursorX_High				0x10
#define OLED_CursorX_Low				0x00
#define OLED_Display_Off				0xAE
#define OLED_SetFreq_High				0xD5
#define OLED_SetFreq_Low				0x80
#define OLED_SetMulRat_High			    0xA8
#define OLED_SetMulRat_Low			    0x3F
#define OLED_SetOffset_High			    0xD3
#define OLED_SetOffset_Low			    0x00
#define OLED_Set_StartLine			    0x40
#define OLED_X_Normal					0xA1
#define OLED_X_Turn						0xA0
#define OLED_Y_Normal					0xC8
#define OLED_Y_Turn						0xC0
#define OLED_OutScanDir_High		    0xDA
#define OLED_OutScanDir_Low			    0x12
#define OLED_ContrastCon_High		    0x81
#define OLED_ContrastCon_Low		    0xCF
#define OLED_PreCharge_High			    0xD9
#define OLED_PreCharge_Low			    0xF1
#define OLED_VCOMHDeLev_High		    0xDB
#define OLED_VCOMHDeLev_Low			    0x30
#define OLED_SetShow_On					0xA4
#define OLED_SetShow_Normal			    0xA6
#define OLED_SetCharPump_High		    0x8D
#define OLED_SetCharPump_Low		    0x14
#define OLED_Display_On					0xAF

#ifndef Font_Add16
#define Font_Add16
#endif

#ifndef Cursor_TypeDef_def
#define Cursor_TypeDef_def
typedef struct
{
	unsigned char Line ;			/*!< The cursor line in the page */
	unsigned char Column ;		    /*!< The cursor column in the line */
}Cursor_TypeDef;
#endif

/* 
* @function: 	OLED_Init
*/
void OLED_Init(void);

/* 
* @function: 	OLED_Clear
*/
void OLED_Clear(void);

/* 
* @function: 	OLED_ShowChar
* @parameter:	[in] Cursor					 Handle to the cursor position.
* @parameter:	[in] show					 The character to be displayed.
*/
void OLED_ShowChar(Cursor_TypeDef* Cursor, char show);

/* 
* @function: 	OLED_ShowString
* @parameter:	[in] Cursor					 Handle to the cursor position.
* @parameter:	[in] String					 The String to be displayed.
*/
void OLED_ShowString(Cursor_TypeDef* Cursor, char* String);

/* 
* @function: 	OLED_ShowChinese
* @parameter:	[in] Cursor					 Handle to the cursor position.
* @parameter:	[in] Chinese				 Handle of the Chinese character to be displayed.
*/
void OLED_ShowChinese(Cursor_TypeDef* Cursor, unsigned int Chinese);

/* 
* @function: 	OLED_ShowChineseString
* @parameter:	[in] Cursor					 Handle to the cursor position.
* @parameter:	[in] Chinese				 Handle of the Chinese character to be displayed.
* @parameter:	[in] num				     The num of the Chinese character to be displayed.
*/
void OLED_ShowChineseString(Cursor_TypeDef* Cursor, unsigned int Chinese, unsigned int num);

/* 
* @function: 	OLED_Printf
* @parameter:	[in] Cursor					 Handle to the cursor position.
* @parameter:	[in] format					 The parameter will be send in OLED_Printf.
*/
void OLED_Printf(Cursor_TypeDef* Cursor, char *format, ...);

#endif

